//
//  UIBarButtonItem+Extension.swift
//  WeiDo
//
//  Created by XISHAN on 16/3/3.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit
    
extension UIBarButtonItem{
    
    convenience init(imageName: String? = nil,title: String? = nil,target: AnyObject? , action:Selector) {
        
        self.init()
        //初始化button
        let btn = UIButton()
        
        //添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        //设置文字
        if let t = title {
        
            btn.setTitle(t, forState: .Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState:.Normal)
            btn.setTitleColor(UIColor(colorLiteralRed: 52/255, green: 52/255, blue: 52/255, alpha: 1), forState:.Highlighted)
            btn.titleLabel?.font = UIFont.systemFontOfSize(16)
            
        }
        //设置图片
        if let name = imageName {
            btn.setImage(UIImage(named: name), forState: .Normal)
            btn.setImage(UIImage(named: "\(name)_highlighted"), forState:.Highlighted)
        }
        btn.sizeToFit()
        customView = btn
    }
    
    
}
